Time series data wrangling and visualization
#loading the packages that I think that I will need for this time series analysis
#Packages for general use:
library(tidyverse)
## -- Attaching packages -------------------------- tidyverse 1.3.0 --
## <U+2713> ggplot2 3.2.1 <U+2713> purrr 0.3.3
## <U+2713> tibble 2.1.3 <U+2713> dplyr 0.8.3
## <U+2713> tidyr 1.0.0 <U+2713> stringr 1.4.0
## <U+2713> readr 1.3.1 <U+2713> forcats 0.4.0
## -- Conflicts ----------------------------- tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(janitor)
##
## Attaching package: 'janitor'
## The following objects are masked from 'package:stats':
##
## chisq.test, fisher.test
library(lubridate)
##
## Attaching package: 'lubridate'
## The following object is masked from 'package:base':
##
## date
library(here)
## here() starts at C:/Users/R. & S. Saldivar/Documents/Bren_School/Class/Winter2020/ESM244/blogdown/Saldivar_Website
##
## Attaching package: 'here'
## The following object is masked from 'package:lubridate':
##
## here
library(RColorBrewer)
library(knitr)
#Packages for time series use:
library(tsibble)
##
## Attaching package: 'tsibble'
## The following objects are masked from 'package:lubridate':
##
## interval, new_interval
## The following object is masked from 'package:dplyr':
##
## id
library(fable)
## Loading required package: fabletools
library(fabletools)
library(feasts)
# Reading in the data that will be analyzed:
steelhead_passage <- read_csv(here("data", "cbr_fish_passage_bonneville_allyrs_steelhead.csv"))
## Parsed with column specification:
## cols(
## year = col_double(),
## `mm-dd` = col_character(),
## location = col_character(),
## parameter = col_character(),
## unit = col_character(),
## datatype = col_character(),
## value = col_double()
## )
Summary of the project. The data for this project is from Columbia Basin Research, which measured the number of Steelhead passing through the Bonneville Dam. The analysis in this markdown down document summarizes the daily, monthly, and annual number of steelhead passing through the Bonneville Dam.
Images of Bonneville Dam and/or steelhead
knitr::include_graphics("images/bonneville-dam-and-people-fishing.jpg")
Figure 1. Peopele Fishing in front of Bonneville Dam. Citation: “Bonneville Dam and people fishing”. goofreephotos.com, accessed 2/20/2020 https://www.goodfreephotos.com/united-states/oregon/other-oregon/bonneville-dam-and-people-fishing.jpg.php
# This code chunk is going to parse and arrange the dates in the data so that it can be separated by months individually and a single column with all of the elements of a date. I am also making sure that each part of the date is treated like a date in R's brain.
steelhead_date <- steelhead_passage %>%
clean_names() %>%
separate(mm_dd, c("day", "month"))
steelhead_date$date <- paste(steelhead_date$year, steelhead_date$month, steelhead_date$day, sep = "-") %>%
ymd() %>%
as.Date()
steelhead_parsed <- steelhead_date %>%
mutate(month = month(date, label = TRUE)) %>%
mutate(month_sep = yearmonth(date)) %>%
drop_na()
#This code chunk is going to create a time series plot of daily observation of steelhead passing through the dam.
steelhead_daily_plot <- ggplot(data = steelhead_parsed, aes(x = date, y = value)) +
geom_line() + #This is the base code to create the graph, now I am going to make the graph look nice
theme_bw() +
labs(x = "Date", y = "Steelhead Passage (fish/day)") +
ggtitle("Daily Steelhead Passage Through Bonneville Dam (1939-2019)")
steelhead_daily_plot
Figure 2. The Daily Steelhead Passage Through Bonneville Dam. The daily passage is faily consistent from 1940 to 2000. After 2000 it the the daily passage appears to increase.
#This code chunk is going to total the monthly counts of steelhead passing through the dam
steelhead_monthly_summary <- steelhead_parsed %>%
group_by(year, month) %>%
summarise(
count = sum(value)
)
#This code chunk is going to explore the monthly passage of steelhead through the dam over time.
steelhead_month_plot <- ggplot(data = steelhead_monthly_summary, aes(x = month, y= count, group = year)) +
geom_line(aes(color = year)) + #This is the base code to create the graph, now I am going to make the graph look nice
theme_bw() +
labs(x = "Month", y = "Steelhead Passage (fish)") +
ggtitle("Monthly Steelhead Passage Through Bonneville Dam (1939-2019)") +
scale_y_continuous() +
scale_color_gradientn(colors = c(
"red",
"orange",
"yellow",
"gold",
"green",
"blue",
"purple",
"violet"
))
steelhead_month_plot
Figure 3. Monthly Steelhead Passage Through Bonneville Dam. Between June and October is when the most Steelhead pass through Bonneville Dam.
#this code chuck i going to summarise the the annual counts of steelhead passage.
steelhead_annual_summary <- steelhead_parsed %>%
group_by(year) %>%
summarise(
count = sum(value)
)
#This code chuck is going to show the annual total of steelhead passing through the dam.
steelhead_annual_plot <- ggplot(data = steelhead_annual_summary, aes(x = year, y = count)) +
geom_line(color = "blue") +
geom_smooth(color = "red",
size = 0.2,
linetype = "dashed",
fill = "red",
alpha = 0.2) +
theme_bw() +
labs(x = "Year", y = "Steelhead Passage (fish)")+
ggtitle("Annual Steelhead Passage Through Bonneville Dam (1939-2019)")
steelhead_annual_plot
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'